<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('渠道信息列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>

                            <li>
                                <label>渠道编号：</label>
                                <input type="text" name="channelCode2"/>
                            </li>

                            <li>
                                <label>渠道名称：</label>
                                <select name="channelCode" class="form-control">
                                    <option value="">所有</option>
                                    <option  th:each="item:${channelInfoList}" th:text="${item.name}" th:value="${item.value}" ></option>
                                </select>
                            </li>

                            <li>
                                <label>渠道类型：</label>
                                <select name="channelType" class="form-control">
                                    <option value="">所有</option>
                                    <option  th:each="item:${channelTypeList}" th:text="${item.name}" th:value="${item.value}" ></option>
                                </select>
                            </li>

                            <li>
                                <label>应用类型：</label>
                                <select name="appType" class="form-control">
                                    <option value="">所有</option>
                                    <option  th:each="item:${appTypeList}" th:text="${item.name}" th:value="${item.value}" ></option>
                                </select>
                            </li>

                            <li>
                                <label>计费类型：</label>
                                <select name="chargeType" class="form-control">
                                    <option value="">所有</option>
                                    <option value="1">UV结算</option>
                                    <option value="2">注册结算</option>
                                    <option value="3">联登结算</option>
                                </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="extend:channel:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-primary" onclick="batchEdit()">-->
<!--                    <i class="fa fa-edit"></i> 批量修改-->
<!--                </a>-->
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="extend:channel:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="extend:channel:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('extend:channel:edit')}]];
        var prefix = ctx + "extend/channel";

        $(function() {
            var options = {
                url: prefix + "/mineList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                modalName: "渠道信息",
                striped: true,
                columns: [
                //     {
                //     checkbox: true
                // },
                // {
                //     field: 'channelCode',
                //     title: '渠道编号'
                // },
                {
                    field: 'channelName',
                    title: '渠道名称（编号）',
                    formatter: function (value,row,index){
                      return row.channelName + ' [ ' + row.channelCode + ' ]';
                    }
                },

                    {
                        field: 'channelType',
                        title: '渠道类型',
                        formatter: function (value,row,index){
                            var reuslt = row.channelTypeStr;
                            if (row.channelType == 'DC'){
                                reuslt = '<span style="color: #1c84c6">'+row.channelTypeStr+'</span>';
                            }else if (row.channelType == 'ZD'){
                                reuslt = '<span style="color: #f3124e">'+row.channelTypeStr+'</span>';
                            }
                            return reuslt;
                        }
                    },
                    {
                        field: 'chargeAmount',
                        title: '价格（比率）',
                        formatter: function (value,row,index){
                            return row.chargeAmount + ' [ ' + row.channelRate + ' ]';
                        }
                    },
                // {
                //     field: 'channelRate',
                //     title: '渠道比率'
                // },
                // {
                //     field: 'owner',
                //     title: '渠道主'
                // },

                {
                    field: 'chargeType',
                    title: '计费类型',
                    formatter: function (value,row,index){
                        var result = 'UV计价';
                        if (row.chargeType == 2){
                            result = '注册计价';
                        }else if (row.chargeType == 3){
                            result = '联登计价';
                        }
                        return result;
                    }
                },
                // {
                //     field: 'unionFlag',
                //     title: '是否联登渠道',
                //     formatter: function (value,row,index){
                //         return row.unionFlag==1?'<span class="badge badge-primary">是</span>':'<span class="badge badge-danger">否</span>';
                //     }
                // },
                {
                    field: 'pageTypeName',
                    title: '推广页类型'
                },
                {
                    // field: 'extUrl',
                    title: '推广链接',
                    formatter: function(value, row, index) {
                        return '<a target="_blank" href="'+row.extUrl+'">'+row.extUrl+'</a>';
                    }
                },
                {
                    field: 'appName',
                    title: '应用名称'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'smsVerifyFlag',
                    title: '是否短信验证',
                    formatter: function (value, row, index) {
                        return statusToolsSms(row);
                    }
                },
                {
                    field: 'adminAccount',
                    title: 'A信息',
                    formatter: function (value, row, index){
                        if (value == undefined || value == ''){
                            return '-';
                        }
                        return '<span style="color: darkgreen; border-bottom: 1px solid" onclick="showAdminInfo(\''+row.adminAccount+'\',\'' +row.adminPasswd+'\')">展示</span>'
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.channelCode + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 用户状态显示 */
        function statusTools(row) {
            if (row.status == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.channelCode + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.channelCode + '\')"></i> ';
            }
        }

        /* 用户管理-停用 */
        function disable(channelCode) {
            $.modal.confirm("确认要停用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "channelCode": channelCode, "status": 0 });
            })
        }

        /* 用户管理启用 */
        function enable(channelCode) {
            $.modal.confirm("确认要启用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "channelCode": channelCode, "status": 1 });
            })
        }


        /*******短信验证*********/
        /* 用户状态显示 */
        function statusToolsSms(row) {
            if (row.smsVerifyFlag == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableSms(\'' + row.channelCode + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableSms(\'' + row.channelCode + '\')"></i> ';
            }
        }

        /* 用户管理-停用 */
        function disableSms(channelCode) {
            $.modal.confirm("确认要关闭短信验证吗？", function() {
                $.operate.post(prefix + "/changeSmsFlag", { "channelCode": channelCode, "smsVerifyFlag": 0 });
            })
        }

        /* 用户管理启用 */
        function enableSms(channelCode) {
            $.modal.confirm("确认要打开短信验证吗？", function() {
                $.operate.post(prefix + "/changeSmsFlag", { "channelCode": channelCode, "smsVerifyFlag": 1 });
            })
        }
        /*******短信验证*********/

        function batchEdit() {
            var url = prefix + "/batchEdit";
            $.modal.open('批量修改', url);
        }

        /**
         * 展示账号信息
         * @param adminAccount
         * @param adminPwd
         */
        function showAdminInfo(adminAccount, adminPwd) {
            var content = '账号：'+ adminAccount +
                '<br>密码：' + adminPwd +
                '<br>登陆地址：http://admin.renxinhua.cn'
            $.modal.alert(content,modal_status.MESSAGE, '注册渠道登陆信息');
        }

    </script>
</body>
</html>